#!/tools/bin/perl
#
#	/********************************************************\
#	 *                                                      *
#	 *              ==========                              *
#	 *             ========  /  Copyright (c) 1997          *
#	 *            ------- / /   Cadence Design Systems Ltd. *
#	 *           ----- / / /                                *
#	 *          --- / / / /	    Spectrum Services.          *
#	 *         / / / / / /                                  *
#	 *         \ \ \ \ \ \      All Rights Reserved         *
#	 *                                                      *
#	\********************************************************/
#
#
#*******************************************************************************
# Filename:	cv2ambit
# Version:	preliminary
# Author:	Paul Martin
#
#
#
#*******************************************************************************


#-------------------------------------------------------------------------------
#GLOBAL VARIABLES
#-------------------------------------------------------------------------------

#$ST20_commonPath="/projects/ST20_common";
$inFileName="cv_ALL";
#$directCvScript="cv_OPUS_netlist";
#$directBuildScript="Build_OPUS_netlist";

#subroutines directory
$subRoutinesDir="/projects/tsunami/project_technology/dtmf/logic/bin/perl_library";

#-------------------------------------------------------------------------------
#load subroutines
#-------------------------------------------------------------------------------
push(@INC,$subRoutinesDir);
require("subroutines.package");
require("findLibPath");




#-------------------------------------------------------------------------------
#
#                        MAIN PROGRAM
#
#-------------------------------------------------------------------------------

#-------------------------------------------------------------------------------
#gets inputs from the command line
#-------------------------------------------------------------------------------
$noverif = "";

for ($index=0;$index<=$#ARGV;$index++)
{
    if ($ARGV[$index] =~ /^-f/)
    {
        $force=$ARGV[$index];
        splice (@ARGV,$index,1);
    } # if
} # for

$libName=$ARGV[0];
$version=$ARGV[1];
$outFileName="$libName.tcl";
print "$outFileName \n";
print "$libName \n";
#-------------------------------------------------------------------------------
#verify the correctness of the input
#-------------------------------------------------------------------------------
unless ($libName) 
{
    print "usage : cv2ambit <libname> [version] [-f]\n";
    print "  the default version is the 'current' version\n";
    print "  -f forces to overwrite $outFileName\n";
    exit;
} # unless

#-------------------------------------------------------------------------------
#gets the full library path and check the existence of the directory
#-------------------------------------------------------------------------------
($libPath,$projectPath)=&getLibFullPath($libName);

#the path points to libname, so we extent it to libname/logic
$libPath = "$libPath/logic";

#checks if the directory xxx/libname/logic exists
unless (-d $libPath) 
{
    print "ERROR : cannot find the directory $libName/logic \n";
    exit;
} # unless

#-------------------------------------------------------------------------------
#checks the correctness of the version
#-------------------------------------------------------------------------------
#$version=&checkVersion($libPath,$version);

#-------------------------------------------------------------------------------
#open the src output file
#-------------------------------------------------------------------------------
#declare variables
$outFilePath="$libPath/bin";
$inFilePath="$libPath/bin";
$inFileType="src";

&openOutputFile(
    $outFilePath,$outFileName,$force,"cv2ambit"
);


#-------------------------------------------------------------------------------
#write the initial section
#-------------------------------------------------------------------------------
print "Creating Ambit build file for $inFileType area...\n";
#print OUTFILE "\# Build - generated automatically by cv2ambit\n\n";
print OUTFILE "\# $libName.tcl - generated automatically by cv2ambit\n\n";

#-------------------------------------------------------------------------------
#scans the cv src file(s)
#-------------------------------------------------------------------------------
# reset global variable
@vhdlCompileFiles=();

&scanCvFileAmbit(
    $inFilePath,
    "",
    $inFileName,
    $inFileType,
    $outFilePath,
    $outFileName,
    "noskip",
    $libName
);


#-------------------------------------------------------------------------------
#Close the script
#-------------------------------------------------------------------------------
close OUTFILE;

#-------------------------------------------------------------------------------
#Set the script to be executable
#-------------------------------------------------------------------------------
chmod(0775,"$outFilePath/$outFileName");



